import { IFrUIContainer } from "../core/IFrUIContainer";
import { Global } from "../../gengine/global/Global";
import { UIComponent } from "../../../fl/core/UIComponent";
import { IToolTipItem } from "../manager/IToolTipItem";
type int = number;
//class UICompomentPool
    
    export  class UICompomentPool
    {
       

        public static get clientDisposeFun(): Function
        {
            return UICompomentPool._clientDisposeFun;
        }

        public static set clientDisposeFun(arg1: Function)
        {
            UICompomentPool._clientDisposeFun = arg1;
            return;
        }

        /* internal  */static getPool(arg1: Class): Array<any>
        {
            if (!(arg1 in UICompomentPool.pools)) 
            {
                var loc1;
                UICompomentPool.pools[arg1] = loc1 = new Array<any>();
            }
            return undefined;
        }

        public static getUICompoment(arg1: Class, ... rest)
        {
            var loc2=null;
            var loc1=UICompomentPool.getPool(arg1);
            if (loc1.length > 0) 
            {
                if ((loc2 = loc1.pop()) is IFrUIContainer) 
                {
                    (loc2 as IFrUIContainer).createDisposedChildren();
                }
                return loc2;
            }
            return com.gengine.utils.pools.construct(arg1, rest);
        }

        public static disposeUICompoment(arg1: Object /* flash.display.DisplayObject */, arg2: Boolean=true, arg3: Class=null): Boolean
        {
            if (UICompomentPool._clientDisposeFun != null) 
            {
                UICompomentPool._clientDisposeFun.call(null, arg1);
            }
            if (!arg1) 
            {
                if (Global.isDebugModle) 
                {
                    throw Error("disposeUIComponent  is  null");
                }
                return false;
            }
            if ((arg1 as Object /* flash.display.DisplayObject */).parent) 
            {
                (arg1 as Object /* flash.display.DisplayObject */).parent.removeChild(arg1 as Object /* flash.display.DisplayObject */);
            }
            if (typeof arg1 === "uicomponent") 
            {
                (arg1 as UIComponent).clearStyle("textFormat");
                (arg1 as UIComponent).clearStyle("disabledTextFormat");
            }
            arg1["visible"] = true;
            arg1["alpha"] = 1;
            arg1["scaleX"] = 1;
            arg1["scaleY"] = 1;
            arg1["rotation"] = 0;
            arg1["filters"] = [];
            if (arg1.hasOwnProperty("enabled")) 
            {
                arg1["enabled"] = true;
            }
            if (arg1 is flash.display.Sprite) 
            {
                (arg1 as Object /* flash.display.Sprite */).graphics.clear();
            }
            if (typeof arg1 === "itooltipitem") 
            {
                (arg1 as IToolTipItem).toolTipData = null;
            }
            if (arg2) 
            {
                UICompomentPool.disposeObject(arg1, arg3);
            }
            return true;
        }

        public static disposeObject(arg1, arg2: Class=null): void
        {
            var loc2=null;
            if (!arg2) 
            {
                loc2 = flash.utils.getQualifiedClassName(arg1);
                arg2 = flash.utils.getDefinitionByName(loc2) as Class;
            }
            var loc1=UICompomentPool.getPool(arg2);
            loc1.push(arg1);
            return;
        }

        public static clearPool(): void
        {
            return;
        }

        public static getSize(): int
        {
            var loc2=undefined;
            var loc1=0;
            var loc3=0;
            var loc4=UICompomentPool.dicObj;
            for(loc2 of loc4) 
            {
                ++loc1;
            }
            return loc1;
        }

        private static /* var */pools: Map<any, any> /* flash.utils.Dictionary */;

        private static /* var */dicObj: Map<any, any> /* flash.utils.Dictionary */;

        private static /* var */_clientDisposeFun: Function;
    }

            UICompomentPool.pools = new Map<any, any> /* flash.utils.Dictionary */();
            UICompomentPool.dicObj = new Map<any, any> /* flash.utils.Dictionary */(true);
        